package com.dragon.mmochat.message;

import java.util.ArrayList;
import java.util.List;

import com.dragon.mmochat.MmochatConstant;
import com.dragon.mmochat.model.role.MmochatFriend;
import com.dragon.mmochat.model.role.MmochatPlayer;
import com.skymobi.buffer.SkymobiBuffer;
import com.skymobi.message.SkymobiProtocolMessage;

public class Mmochat_10_1S extends SkymobiProtocolMessage {
	MmochatPlayer me;
	private List<MmochatFriend> myFriends = new ArrayList<MmochatFriend>();
	private List<MmochatFriend> enermies = new ArrayList<MmochatFriend>();

	public Mmochat_10_1S() {
		setMsgCode(MmochatConstant.MSGCODE_MMOCHAT_S_10_1);
	}

	@Override
	protected void encodeBody(SkymobiBuffer out) {
		out.putShort((short) (myFriends.size() + 1));
		// 把自己也当成好友处理，第一个下发
		{
			out.putInt(me.getRoleId());
			out.putInt(Integer.MAX_VALUE);
			out.putUnsignedShort(me.getBmpId());
			if (me.isVip()) {
				out.put((byte) 1);
			} else {
				out.put((byte) 0);
			}
			out.put((byte) 1);
			out.putPrefixedString(me.getName(), 1);
		}
		for (MmochatFriend friend : myFriends) {
			out.putInt(friend.getRoleId());
			out.putInt(friend.getFriendListPrority());
			out.putUnsignedShort(friend.getBmpId());
			if (friend.isVip()) {
				out.put((byte) 1);
			} else {
				out.put((byte) 0);
			}
			out.put((byte) friend.getFriendState(me));
			out.putPrefixedString(friend.getName(), 1);
		}

		out.putShort((short) enermies.size());
		for (MmochatFriend friend : enermies) {
			out.putInt(friend.getRoleId());
			out.putInt(friend.getFriendListPrority());
			out.putUnsignedShort(friend.getBmpId());
			if (friend.isVip()) {
				out.put((byte) 1);
			} else {
				out.put((byte) 0);
			}
			out.put((byte) friend.getFriendState(me));
			out.putPrefixedString(friend.getName(), 1);
		}
	}

	public void setMyFriends(List<MmochatFriend> myFriends) {
		this.myFriends = myFriends;
	}

	public void setEnermies(List<MmochatFriend> enermies) {
		this.enermies = enermies;
	}

	public void setMe(MmochatPlayer me) {
		this.me = me;
	}

}
